<template>
<div>
  <p>注册名：<input type="text" name="user_name" id="user_name" v-model="form.username" @blur="checkusername"></p>
  <span class="error_tip">{{error.username}}</span>
  <p>密码:<input type="text" v-model="form.password" @blur="checkpassword"></p>
  <p>{{error.password}}</p>
  <p>手机号<input type="text" v-model="form.mobile" @blur="checkmobile"></p>
  <p>{{error.mobile}}</p>
</div>
</template>

<script>
export default {
  name: "day03",
  data(){
    return{
      form:{},
      error:{username:'',password:'',mobile:''}
    }
  },
  methods:{
    checkusername(){
      var m = this.form.username
      if(m==undefined){
        this.error.username='必须输入用户名'
        return false
      }
      let reg = /\w{5,10}$/
      if(!reg.test(m)){
        this.error.username='请输入正确格式'
        return false
      }
      this.$axios.post('users/user/',this.form.username)
      .then(res=>{
        if(res.data.code==10010){
          this.error.username='必须输入用户名'
        }
        if (res.data.code==10011){
          this.error.username='用户名格式不对'
        }
        if (res.data.code==10012){
          this.error.username='用户已存在'
        }
      })

    },
    checkpassword(){

    },
    checkmobile(){
      var r = this.form.mobile
      if(r==undefined){
        this.error.mobile='请输入电话号码'
      }
      let v = /^1[3-9]\d{9}$/
      if(!v.test(r)){
        this.error.mobile='请输入正确格式'
      }
      this.$axios.post('users/user/',this.form.mobile)
      .then(res=>{
        if(res.data.code==10013){
          this.error.mobile='请输入手机号'
        }
        if(res.data.code==10014){
          this.error.mobile='手机号格式不对'
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
